package com.fzhiyu.xiaofengblog.controller.system;

import com.fzhiyu.xiaofengblog.common.core.controller.BaseController;
import com.fzhiyu.xiaofengblog.common.core.domain.AjaxResult;
import com.fzhiyu.xiaofengblog.common.core.page.TableDataInfo;
import com.fzhiyu.xiaofengblog.domain.system.User;
import com.fzhiyu.xiaofengblog.service.system.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/userInfo")
public class UserController extends BaseController {
    @Autowired
    private IUserService userService;
    private BaseController baseController;

    /**
     * 查询用户信息列表
     * @param user 设备信息
     * @return 设备信息列表
     */
    @GetMapping("/list")
    public TableDataInfo userList(User user){
        List<User> users = userService.selectUserList(user);
        return getDataTable(users);
    }

    /**
     * 获取用户信息详细信息
     */
    @GetMapping("/{id}")
    public AjaxResult getUserInfo(@PathVariable("id") Long id){

        System.out.println(id);
        System.out.println(userService.selectUserById(id));
        return AjaxResult.success(userService.selectUserById(id));
    }

    /**
     * 新增设备信息
     */

    @PostMapping
    public AjaxResult addUserInfo(@RequestBody User user){
        return toAjax(userService.insertUser(user));
    }
    /**
     * 修改设备信息
     */

    @PutMapping
    public AjaxResult editUserInfo(@RequestBody User user){
        return toAjax(userService.updateUser(user));
    }

    /**
     * 删除设备信息
     */

    public AjaxResult remove(Long[] ids){
        return toAjax(userService.deleteUserByIds(ids));
    }

}
